﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using DiagnosticCenter.Web;
using Telerik.Windows.Controls;

namespace DiagnosticCenter.View
{
    public partial class viewOperatorUsers : Page
    {
        public viewOperatorUsers()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ChangeGridView(1);
        }

        private void RadContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            var numb = (e.OriginalSource as RadMenuItem).Tag.ToString();
            switch (numb)
            {
                case "1":
                    ChangeGridView(1);
                    break;
                case "2":
                    ChangeGridView(2);
                    break;
                case "3":
                    ChangeGridView(3);
                    break;
            }
        }

        public void ChangeGridView(int mode = 1)
        {
            gridStudents.Columns.Clear();
            switch (mode)
            {
                case 1:
                    gridStudents.Columns.Add(AddNewColumn("Фамилия", 100, "LastName"));
                    gridStudents.Columns.Add(AddNewColumn("Имя", 100, "FirstName"));
                    gridStudents.Columns.Add(AddNewColumn("Отчество", 100, "MiddleName"));
                    gridStudents.Columns.Add(AddNewColumn("Пол", 60, "Sex", new SexConverter()));
                    gridStudents.Columns.Add(AddNewColumn("ДР", 80, "Birthdate", new DateConverter()));
                    gridStudents.Columns.Add(AddNewColumn("Телефон", 80, "Phone"));
                    gridStudents.Columns.Add(AddNewColumn("Город", 90, "City"));
                    gridStudents.Columns.Add(AddNewColumn("Адрес", 120, "Address"));
                    gridStudents.Columns.Add(AddNewColumn("Email", 150, "Email"));
                    break;
                case 2:
                    gridStudents.Columns.Add(AddNewColumn("Фамилия", 100, "LastName"));
                    gridStudents.Columns.Add(AddNewColumn("Имя", 100, "FirstName"));
                    gridStudents.Columns.Add(AddNewColumn("Отчество", 100, "MiddleName"));
                    gridStudents.Columns.Add(AddNewColumn("Кафедра", 60, "ChairName"));
                    gridStudents.Columns.Add(AddNewColumn("Вид обучения", 90, "tblGroup.StudyKind"));
                    gridStudents.Columns.Add(AddNewColumn("Специальность", 80, "tblGroup.Speciality"));
                    gridStudents.Columns.Add(AddNewColumn("Группа", 80, "tblGroup.Name"));
                    gridStudents.Columns.Add(AddNewColumn("Курс", 80, "tblGroup.Course"));
                    gridStudents.Columns.Add(AddNewColumn("Степень", 80, "DigreeName"));
                    gridStudents.Columns.Add(AddNewColumn("Рейтинг", 90, "AverageRating"));
                    gridStudents.Columns.Add(AddNewColumn("Оплата", 90, "Payment", new PaymentConverter()));
                    break;
                case 3:
                    gridStudents.Columns.Add(AddNewColumn("Фамилия", 100, "LastName"));
                    gridStudents.Columns.Add(AddNewColumn("Имя", 100, "FirstName"));
                    gridStudents.Columns.Add(AddNewColumn("Отчество", 100, "MiddleName"));
                    gridStudents.Columns.Add(AddNewColumn("Темперамент", 100, "PsyxTemperament", new TemperamentConverter()));
                    gridStudents.Columns.Add(AddNewColumn("Мотивация", 80, "PsyxMotivation", new MotivationConverter()));
                    gridStudents.Columns.Add(AddNewColumn("Общительность", 80, "PsyxSociality", new SocialityConverter()));
                    break;
            }
        }

        public GridViewDataColumn AddNewColumn(string title, int width, string binding, IValueConverter converter = null)
        {
            var gb = new GridViewDataColumn();
            gb.Header = title;
            gb.Width = width;
            gb.DataMemberBinding = new Binding { Path = new PropertyPath(binding), Converter = converter };
            return gb;
        }

        private void DomainDataContext_LoadedData(object sender, LoadedDataEventArgs e)
        {
            if (e.HasError)
            {
                MessageBox.Show(e.Error.ToString(), "Load Error", MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            //UserDataContext.QueryParameters.Clear();
            //UserDataContext.QueryParameters.Add(new Parameter
            //{
            //    ParameterName = "groupid",
            //    Value = (groupBox.SelectedItem as tblGroup).GroupID
            //});

            //if (UserDataContext.CanLoad) UserDataContext.Load();
        }
    }
}

//TODO: NEW: добавить новый Page с подробной информацией о каждом студенте
//TODO: ADD: добавить фильтры